*******************************************************************************
*Replication File: EU Analysis
*******************************************************************************
*For use with EU.dta
**Variable information can be found in Codebook tab Europe
		
********************************************************************************
*Data preparation
********************************************************************************		

*Variable for National Suffrage
gen NoNational = 0
replace NoNational = 1 if rcou != "PRT" & rcou != "GBR" //for national suffrage 

********************************************************************************
*Data analysis
********************************************************************************

*Baseline Model
eststo main_1: qui mixed IHS_citacq  municipal ///
	ln_migflow ln_stockvalue  i.year i.scode ///
	|| rscode:,  cluster(rscode) 
*Model with Policy Variation
eststo main: qui mixed IHS_citacq rmpoliticalNIS10  municipal dualcit ///
	ln_migflow ln_stockvalue i.year i.scode ///
	|| rscode: ,  cluster(rscode) 
*Model with All Covariates
eststo covariates: qui mixed IHS_citacq rmpoliticalNIS10 municipal dualcit i.year ///
	ln_migflow ln_stockvalue rmaccess_nodcgen10 ///
	rmlaboraccess10 Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno i.scode ///
	|| rscode:, cluster(rscode) 
	
*Baseline Model - excluding National Suffrage
eststo main_1R: qui mixed IHS_citacq  municipal ///
	ln_migflow ln_stockvalue i.year i.scode ///
	if NoNational == 1 || rscode:, cluster(rscode)
*Model with Policy Variation - excluding National Suffrage
eststo main_R: qui mixed IHS_citacq rmpoliticalNIS10  municipal dualcit ///
	ln_migflow ln_stockvalue i.year i.scode ///
	if NoNational == 1 || rscode:, cluster(rscode) 
*Model with All Covariates - excluding National Suffrage
eststo covariates_R: qui mixed IHS_citacq rmpoliticalNIS10  municipal dualcit i.year ///
	ln_migflow ln_stockvalue rmaccess_nodcgen10 ///
	rmlaboraccess10 Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno i.scode ///
	if NoNational == 1 || rscode:, cluster(rscode) 

*Baseline Model - including Universal Enfranchisement only
eststo main_1U: qui mixed IHS_citacq  municipal ///
	ln_migflow ln_stockvalue i.year i.scode ///
	if NoNational == 1 & rcou!= "ESP" || rscode:, cluster(rscode) 
*Model with Policy Variation - including Universal Enfranchisement only
eststo main_U: qui mixed IHS_citacq rmpoliticalNIS10  municipal dualcit ///
	ln_migflow ln_stockvalue i.year i.scode ///
	if NoNational == 1 & rcou!= "ESP" || rscode:, cluster(rscode) 
*Model with All Covariates - including Universal Enfranchisement only
eststo covariates_U: qui mixed IHS_citacq rmpoliticalNIS10  municipal dualcit i.year ///
	ln_migflow ln_stockvalue rmaccess_nodcgen10 ///
	rmlaboraccess10 Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno i.scode ///
	if NoNational == 1 & rcou!= "ESP" || rscode:, cluster(rscode) 

*Baseline Model with Policy Variation - alternative Dual Citizenship Coding
eststo main1_dc: qui  mixed IHS_citacq rmpoliticalNIS10  municipal dualcit_c ///
	ln_migflow ln_stockvalue i.year i.scode ///
	|| rscode:, cluster(rscode) 
*Model with All Covariates - alternative Dual Citizenship Coding
eststo main2_dc: qui mixed IHS_citacq rmpoliticalNIS10  municipal dualcit_c i.year ///
	ln_migflow ln_stockvalue rmaccess_nodcgen10  ///
	rmlaboraccess10 Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno i.scode ///
	|| rscode:, cluster(rscode) 
	
*Baseline Model Model with Policy Variation - Within-Between Random Effects
eststo REWB_1: qui xthybrid IHS_citacq  ///
	rmpoliticalNIS10  municipal dualcit ln_migflow ln_stockvalue ///
	if rdc != . & sdc != . & NoNational == 1, ///
	clusterid(rscode) vce(robust) se test full 
*Model with All Covariates - Within-Between Random Effects
eststo REWB_covariates: qui xthybrid IHS_citacq rmlaboraccess10 ///
	rmpoliticalNIS10  municipal	dualcit ln_migflow ln_stockvalue ///
	rmaccess_nodcgen10 Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno  ///
	if NoNational == 1, clusterid(rscode) vce(robust) se test full 
	
*Robust Rate Model with All Covariates - Logical Stock
eststo robustrateS_logical: qui mixed IHS_propcitB rmpoliticalNIS10 municipal ///
	dualcit i.year ///
	ln_migflow rmaccess_nodcgen10 ///
	rmlaboraccess10 Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno i.scode ///
	if propcitB <= 100 || rscode:, cluster(rscode) 
*Robust Rate Model with All Covariates - Exceeding 100% Stock
eststo robustrateS: qui mixed IHS_propcitB rmpoliticalNIS10 municipal ///
	dualcit i.year ///
	ln_migflow rmaccess_nodcgen10 ///
	rmlaboraccess10 Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno i.scode ///
	|| rscode:, cluster(rscode) 
*Robust Model with All Covariates - Immigrant Stock 
eststo robustS: qui mixed IHS_cit rmpoliticalNIS10 municipal dualcit i.year ///
	ln_migflow ln_bilateralstock1 rmaccess_nodcgen10 ///
	rmlaboraccess10 Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno i.scode ///
	|| rscode:, cluster(rscode) 
*Robust Rate Model with All Covariates - Logical Residents
eststo robustrateR_logical: qui mixed IHS_propcitBR rmpoliticalNIS10 municipal dualcit i.year ///
	ln_migflow rmaccess_nodcgen10 ///
	rmlaboraccess10 Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno i.scode ///
	if propcitR <= 100|| rscode:, cluster(rscode) 
*Robust Rate Model with All Covariates - Exceeding 100% Residents
eststo robustrateR: qui mixed IHS_propcitBR rmpoliticalNIS10 municipal dualcit i.year ///
	ln_migflow rmaccess_nodcgen10 ///
	rmlaboraccess10 Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno i.scode ///
	|| rscode:, cluster(rscode) 
*Robust Model with All Covariates - Immigrant Residents 
eststo robustR: qui mixed IHS_cit rmpoliticalNIS10 municipal dualcit i.year ///
	ln_migflow ln_bilateralres rmaccess_nodcgen10 ///
	rmlaboraccess10 Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno i.scode ///
	|| rscode:, cluster(rscode) 
			
********************************************************************************
*Appendix Table A.2.5
********************************************************************************

sum municipal rmpoliticalNIS10 dualcit rmaccess_nodcgen10 rmlaboraccess10 ///
	ln_migflow ln_stockvalue Ll1rgdp l1runemp ///
	Ll1sgdp l1sunemp spolity2 colony comlang_ethno ///
	Asia Europe SCAmerica NAmerica Africa Oceania MENA 

********************************************************************************
*Appendix Table B.2.1
********************************************************************************

esttab main_1 main covariates using appendixb21.tex, se(3) b(3) aic ///
	nogaps star(+ 0.1 * 0.05 ** 0.01) ///
	refcat(municipal "\textit{Destination Effects}" Ll1sgdp "\textit{Origin Effects}", ///
	nolabel) drop(*.year lns1_1_1:_cons lnsig_e:_cons) ///
	order(municipal ln_migflow ln_stockvalue ///
		rmpoliticalNIS10 dualcit rmaccess_nodcgen10 rmlaboraccess10 Ll1rgdp l1runemp ///
		Ll1sgdp l1sunemp spolity2 colony comlang_ethno) ///
	indicate(Fixed Effects = *scode, labels("Origin \& Year " "--")) ///
	label nonumbers mtitles("1" "2" "3") ///
	addnotes("Unstandardized beta coefficients with robust clustered standard errors in parentheses." ///
	"+p < 0.10 * p < 0.05, ** p < 0.01.") nonotes replace
	
********************************************************************************	
*Appendix Table C.2.1
********************************************************************************

esttab main_1R main_R covariates_R using appendixc21.tex, se(3) b(3) aic ///
	nogaps star(+ 0.1 * 0.05 ** 0.01) ///
	refcat(municipal "\textit{Destination Effects}" Ll1sgdp "\textit{Origin Effects}", ///
	nolabel) drop(*.year lns1_1_1:_cons lnsig_e:_cons) ///
	order(municipal ln_migflow ln_stockvalue ///
		rmpoliticalNIS10 dualcit rmaccess_nodcgen10 rmlaboraccess10 Ll1rgdp l1runemp ///
		 Ll1sgdp l1sunemp spolity2 colony comlang_ethno) ///
	indicate(Fixed Effects = *scode, labels("Origin \& Year " "--")) ///
	label nonumbers mtitles("1" "2" "3") ///
	addnotes("Unstandardized beta coefficients with robust clustered standard errors in parentheses." ///
	"+p < 0.10 * p < 0.05, ** p < 0.01.") nonotes replace

********************************************************************************
*Appendix Table C.2.2
********************************************************************************
esttab main_1U main_U covariates_U using appendixc22.tex, se(3) b(3) aic ///
	nogaps star(+ 0.1 * 0.05 ** 0.01) ///
	refcat(municipal "\textit{Destination Effects}" Ll1sgdp "\textit{Origin Effects}", ///
	nolabel) drop(*.year lns1_1_1:_cons lnsig_e:_cons) ///
	order(municipal ln_migflow ln_stockvalue ///
		rmpoliticalNIS10 dualcit rmaccess_nodcgen10 rmlaboraccess10 Ll1rgdp l1runemp ///
		 Ll1sgdp l1sunemp spolity2 colony comlang_ethno) ///
	indicate(Fixed Effects = *scode, labels("Origin \& Year " "--")) ///
	label nonumbers mtitles("1" "2" "3") ///
	addnotes("Unstandardized beta coefficients with robust clustered standard errors in parentheses." ///
	"+p < 0.10 * p < 0.05, ** p < 0.01.") nonotes replace
	
********************************************************************************
*Appendix Table C.2.3	
********************************************************************************

esttab main1_dc main2_dc using appendixc23.tex, se(3) b(3) aic ///
	nogaps star(+ 0.1 * 0.05 ** 0.01) ///
	refcat(municipal "\textit{Destination Effects}" sdc "\textit{Origin Effects}", ///
	nolabel) drop(*.year lns1_1_1:_cons lnsig_e:_cons) ///
	indicate(Fixed Effects = *scode, labels("Origin \& Year " "--")) ///
	order(municipal ln_migflow ln_stockvalue ///
		rmpoliticalNIS10 dualcit_c rmaccess_nodcgen10 rmlaboraccess10 Ll1rgdp l1runemp ///
		Ll1sgdp l1sunemp spolity2 colony comlang_ethno) ///
	label nonumbers mtitles("1" "2" "3") ///
	addnotes("Unstandardized beta coefficients with robust clustered standard errors in parentheses." ///
	"+p < 0.10 * p < 0.05, ** p < 0.01.") nonotes replace

********************************************************************************
*Appendix Table C.2.4 
********************************************************************************

esttab REWB_1 REWB_1 REWB_covariates REWB_covariates using appendixc24.rtf, se(3) b(3) aic ///
	nogaps star(+ 0.1 * 0.05 ** 0.01) ///
	coeflabels(R__municipal "Municipal Suffrage" ///
		R__ln_stockvalue "Migrant stock (log)" ////
		W__ln_migflow "Migrant flow (log)" ///
		W__rmpoliticalNIS10 "Political Representation" W__rdc "Dual citizenship" ///
		W__sdc "Dual citizenship" ///
		R__Ll1rgdp "Destination Log GDP pc\testsubscript{t-1}" ///
		R__Ll1sgdp "Origin Log GDP pc\testsubscript{t-1}" ///
		R__comlang_ethno "Common Language" R__colony "Colonial relationship" ///
		W__l1runemp "Unemployment\textsubscript{t-1}" ///
		W__rmaccess_nodcgen10 "Acquisition Ease" ///
		W__rmlaboraccess10 "Labor Market Access" ///
		W__l1sunemp "Unemployment\textsubscript{t-1}" ///
		W__spolity2 "Democratic quality") ///
		order(W__rmpoliticalNIS10 W__rdc W__ln_migflow ///
			W__l1runemp W__rmaccess_nodcgen10 W__rmlaboraccess10 ///
			 W__l1sunemp W__spolity2 ///
			B__rmpoliticalNIS10  B__ln_migflow  ///
			B__l1runemp B__rmaccess_nodcgen10 B__rmlaboraccess10 ///
			 B__l1sunemp B__spolity2 ///
			R__municipal F_dualcit R__ln_stockvalue R__Ll1rgdp R__Ll1sgdp ///
			R__comlang_ethno R__colony) ///
		refcat(R__municipal "\textit{Random Effects}" ///
			W__rmpoliticalNIS10 "\testit{Destination Effects}" ///
			W__l1sunemp "\textit{Origin Effects}", ///
		nolabel) ///
		label nonumbers mgroups("1" "2") ///
		mtitles("Within" "Between" "Within" "Between") ///
	addnotes("Unstandardized beta coefficients with robust clustered standard errors in parentheses." ///
	"+p < 0.10 * p < 0.05, ** p < 0.01.") nonotes replace
	
********************************************************************************
*Appendix Table C.2.5
********************************************************************************
	
esttab robustrateS_logical robustrateR_logical robustrateS robustrateR robustS robustR using appendixc25.tex, se(3) b(3) aic ///
	nogaps star(+ 0.1 * 0.05 ** 0.01) ///
	mgroups("\textit{Citizenship 'Rate'}" "\textit{Citizenship acquisitions}", ///
		pattern(1 0 0 0 1 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(})span)  ///
	refcat(municipal "\textit{Destination Effects}" Ll1sgdp "\textit{Origin Effects}", ///
	nolabel) drop(*.year lns1_1_1:_cons lnsig_e:_cons) ///
	indicate(Fixed Effects = *scode, labels("Origin \& Year " "--")) ///
	order(municipal ln_migflow ln_bilateralstock1 ln_bilateralres ///
		rmpoliticalNIS10 dualcit rmaccess_nodcgen10 rmlaboraccess10 Ll1rgdp l1runemp ///
		Ll1sgdp l1sunemp spolity2 colony comlang_ethno) ///
	label nonumbers mtitles("Stock" "Residents" "Stock" "Residents" "Stock" "Residents") ///
	addnotes("Unstandardized beta coefficients with robust clustered standard errors in parentheses." ///
	"+p < 0.10 * p < 0.05, ** p < 0.01.") nonotes replace

********************************************************************************
*Figure 4
********************************************************************************
graph set window fontface "Helvetica" 

label variable Ll1rgdp "Log GDP pc{subscript:t-1}"
label variable l1runemp "Unemployment{subscript:t-1}"
label variable l1sunemp "Unemployment{subscript:t-1}"
label variable Ll1sgdp "Log GDP pc{subscript:t-1}"

coefplot (main_1, label(w/o covariates) color("84 39 143") ///
		drop(*.scode _cons *.year) msymbol(O) msize(vsmall) levels(95 90) ///
		ciopts(lcolor("84 39 143" "84 39 143") lwidth(.2 .4)) citop offset(.3)) ///
	(main,  label(w/political rights) color("117 107 177") ///
		drop(*.scode _cons *.year) msymbol(d) msize(small) levels(95 90) ///
		ciopts(lcolor("117 107 177" "117 107 177") lwidth(.2 .4)) citop) ///
	(covariates, label(w/covariates) color("188 189 220") ///
		drop(*.scode _cons *.year) msymbol(s) msize(small) levels(95 90) ///
		ciopts(lcolor("188 189 220" "188 189 220") lwidth(.2 .4))citop offset(-.3)), ///
	order(municipal dualcit ln_migflow ln_stockvalue ///
		rmpoliticalNIS10 rdc rmaccess_nodcgen10 rmlaboraccess10 Ll1rgdp l1runemp ///
		sdc Ll1sgdp l1sunemp spolity2 colony comlang_ethno) ///
	headings(municipal= "{bf:Destination Effects}" ///
		Ll1sgdp = "{bf:Origin Effects}", labsize(small)) ///
	xline(0, lcolor(black)) ///
	ylabel(, labsize(vsmall)) ///
	grid(glcolor(gs12) glpattern("dot")) ///
	coeflabels(, notick) ///
	legend(col(1) subtitle("{bf:Model}", size(small)) region(lcolor(black)) ///
		position(1) ring(0) size(vsmall)) ///
	graphregion(color(white)) ///
	plotregion(lcolor(black))

graph export Figure4.png, replace
